package com.lanou.horo.zhuizhui.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.lanou.horo.zhuizhui.utility.imageLoader.VolleySingleton;
import com.lanou.horo.zhuizhui.R;

/**
 * Created by dllo on 15/11/3.
 */
public class DialogFragmentPage extends Fragment {
    private RequestQueue queue;
    private Context context;
    private ImageLoader imageLoader;
    private NetworkImageView dialogImageView;
    private String dialogName, dialogAuthor, dialogCategoryName,
            dialogUpdate, dialogLastVolume, dialogImage, dialogRanking;
    private TextView dialogNameTV, dialogAuthorTV, dialogCategoryNameTV,
            dialogUpdateTV, dialogLastVolumeTV, dialogRankingTV;

    private static DialogFragmentPage DialogFragmentPage;

    private DialogFragmentPage() {
        imageLoader = VolleySingleton.getInstance().getImageLoader();
    }

    public static DialogFragmentPage getInstance(String dialogName, String dialogImage,String dialogAuthor, String dialogCategoryName,
          String dialogUpdate, String dialogLastVolume,String dialogRanking ) {

        DialogFragmentPage dialogFragmentPage = new DialogFragmentPage();
        Bundle args = new Bundle();
        args.putString("dialogName", dialogName);
        args.putString("dialogAuthor", dialogAuthor);
        args.putString("dialogCategoryName", dialogCategoryName);
        args.putString("dialogUpdate", dialogUpdate);
        args.putString("dialogLastVolume", dialogLastVolume);
        args.putString("dialogImage", dialogImage);
        args.putString("dialogRanking",dialogRanking);
        dialogFragmentPage.setArguments(args);

        return dialogFragmentPage;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null) {
            dialogName = bundle.getString("dialogName");
            dialogAuthor = bundle.getString("dialogAuthor");
            dialogCategoryName = bundle.getString("dialogCategoryName");
            dialogUpdate = bundle.getString("dialogUpdate");
            dialogLastVolume = bundle.getString("dialogLastVolume");
            dialogImage = bundle.getString("dialogImage");
            dialogRanking = bundle.getString("dialogRanking");
        }
    }

    @Override
    @Nullable
    public View onCreateView(LayoutInflater inflater,
                             @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_dialog, null);

        dialogImageView = (NetworkImageView) v.findViewById(R.id.dialogImage);
        dialogNameTV = (TextView) v.findViewById(R.id.dialogName);
        dialogAuthorTV = (TextView) v.findViewById(R.id.dialogAuthor);
        dialogCategoryNameTV = (TextView) v.findViewById(R.id.dialogCategoryName);
        dialogUpdateTV = (TextView) v.findViewById(R.id.dialogUpdate);
        dialogLastVolumeTV = (TextView) v.findViewById(R.id.dialogLastVolume);
        dialogRankingTV = (TextView) v.findViewById(R.id.dialogRanking);

        dialogNameTV.setText(dialogName);
        dialogAuthorTV.setText("作者:"+dialogAuthor);
        dialogCategoryNameTV.setText("类型:"+dialogCategoryName);
        dialogUpdateTV.setText("更新:"+dialogUpdate);
        dialogLastVolumeTV.setText("更新至:"+dialogLastVolume);
        dialogRankingTV.setText(dialogRanking);
        dialogImageView.setImageUrl(dialogImage, imageLoader);

        return v;
    }

}
